package com.powerteam.mapper.crm;

import com.powerteam.model.crm.ContactsRole;
import com.powerteam.model.crm.Opportunity;
import com.powerteam.vo.crm.QueryOpportunityVO;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.Map;

/**
 * 机会表相关的操作
 *
 * @author jinming.zhang
 * @version 0.0.1
 * @date 2021/12/30
 */
@Mapper
public interface OpportunityMapper {

    /**
     * 创建业务机会
     *
     * @param opportunity
     * @return boolean
     * @Author jinming.zhang
     * @Date 2022/1/6
     */
    int insert(Opportunity opportunity);

    /**
     * 查询机会信息
     *
     * @param vo
     * @Author jinming.zhang
     * @Date 2022/1/7
     * @return List<Opportunity>
     */
    List<Opportunity> find(QueryOpportunityVO vo);

    /**
     * 根据Id查询业务机会详情
     *
     * @param opportunityId
     * @Author jinming.zhang
     * @Date 2022/1/7
     * @return Opportunity
     */
    Opportunity findById(Integer opportunityId);

    /**
     * 更新/修改业务机会
     *
     * @param opportunity
     * @Author jinming.zhang
     * @Date 2022/1/7
     * @return int
     */
    int update(Opportunity opportunity);

    /**
     * 添加联系人信息
     *
     * @param contactsRole
     * @Author jinming.zhang
     * @Date 2022/1/7
     * @return int
     */
    int insertContactsRole(ContactsRole contactsRole);

    /**
     * 修改联系人角色
     *
     * @param contactsRole
     * @Author jinming.zhang
     * @Date 2022/1/7
     * @return int
     */
    int updateContactsRole(ContactsRole contactsRole);

    /**
     * 移除联系人角色
     *
     * @param contactsRole
     * @Author jinming.zhang
     * @Date 2022/1/7
     * @return int
     */
    int deleteContactsRole(ContactsRole contactsRole);

    /**
     * 删除业务机会
     *
     * @param opportunity
     * @Author jinming.zhang
     * @Date 2022/1/7
     * @return int
     */
    int delete(Opportunity opportunity);

    /**
     * 查询本月我参与的业务机会
     *
     * @param vo
     * @Author jinming.zhang
     * @Date 2022/1/8
     * @return List<Map < String, Integer>>
     */
    @MapKey(value = "")
    List<Map<String, Integer>> findMonthlyFunnel(QueryOpportunityVO vo);

    /**
     * 查询本月我的转化情况
     *
     * @param vo
     * @Author jinming.zhang
     * @Date 2022/1/8
     * @return List<Map < String, Integer>>
     */
    @MapKey(value = "")
    List<Map<String, Integer>> findMonthlyConversion(QueryOpportunityVO vo);

    /**
     * 查询将要结束的业务机会(最近一周没有关闭的业务机会)
     *
     * @param vo
     * @Author jinming.zhang
     * @Date 2022/1/8
     * @return List<Opportunity>
     */
    List<Opportunity> findRecentlyClosing(QueryOpportunityVO vo);
}
